package divinity.basic
{
	import flash.display.*;
	import flash.events.Event;
	import flash.globalization.*;
	public class DivinityObject extends Sprite
	{
		private static var _log:String="";
		private var _addedListeners:Array=[];
		private var _added:int=0;;
		private var _removed:int=0;	
		
		public function DivinityObject()
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE,init);
			log="Created";
			
		}
		/**
		 * 
		 * INIT FUNCTION
		 * 
		 * */
		public function init(e:Event)
		{
			log="Added";
			this.removeEventListener(Event.ADDED_TO_STAGE,init);
			this.addEventListener(Event.REMOVED_FROM_STAGE,destroy);
			
		}
		/**
		 * 
		 * DESTORY FUNCTION
		 * 
		 * */
		public function destroy(e:Event)
		{				 
			
			this.removeEventListener(Event.REMOVED_FROM_STAGE,destroy);
			log="Destroyed with "+getActiveListeners()+" listeners";
		}
		override public function addChild(child:DisplayObject):DisplayObject
		{
			super.addChild(child);	
			log="<----"+child+" <"+child.name+"> added with addChild";
			return this;
			
		}
		override public function addChildAt(child:DisplayObject,index:int):DisplayObject
		{
			super.addChildAt(child,index);	
			log="<----"+child+" <"+child.name+"> added with addChild";
			return this;
			
		}
		override public function removeChild(child:DisplayObject):DisplayObject
		{
			super.removeChild(child);
			log="---->"+child+" <"+child.name+"> removed with removeChild";
			return this;
		}
		/*
		* 
		*
		*
		*
		*
		*
		*/
		override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
		{
			super.addEventListener(type,listener,useCapture,priority,useWeakReference);
			_added++;
			_addedListeners.push(type)
		}
		override public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
		{
			super.removeEventListener(type,listener,useCapture);
			_removed++;
		}
		public function getActiveListeners()
		{
			var a:String="added: "+_added+"|removed: "+_removed+"";
			
			return a;
		}
		public function set log(str:String):void
		{
			
			var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.SHORT, DateTimeStyle.SHORT);				
			var currentDate:Date = new Date();
			var shortDate:String = df.format(currentDate);			
			_log+="["+shortDate+"]:{"+this.name+"} "+this+":		"+str+"\n";
		}
		public function get log():String
		{
			return _log;
		}
	}
}